Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: allow client redirects via 302 responses (#3130) #3131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FergusInLondon
Copy link

This commit changes the behaviour of the webhook filter when a 302 Found response is received from the AuthN/AuthZ endpoint. As a result, it allows front-end facing (i.e. non-API) traffic to be filtered via the webhook.

Documentation updates and increased test coverage are included.

Incidental: Prevent the webhook client from following redirects from the AuthN/AuthZ endpoint: during testing I realised that the default net/http behaviour was in use - i.e. redirects were followed. Is this an intended behaviour of the filter: it's not documented, and it seems potentially risky?

Please take a look at #3130 for more details.


Changes:

  1. Update to the documentation - filters.md.
  2. Update to the auth reject() function, whereby the Location header is forwarded to the client if a 302 is encountered from the AuthN/AuthZ endpoint.
  3. Prevent the webhook filter from following 302 redirects.
  4. Update tests to cover 302 redirect forwarding.

This commit changes the behaviour of the webhook filter when a 302 Found
response is recieved from the AuthN/AuthZ endpoint. As a result, it allows
front-end facing (i.e. non-API) traffic to be filtered via the webhook.

Documentation updates and increased test coverage is included.

Incidental: Prevent the webhook client from following redirects from the
AuthN/AuthZ endpoint: during testing I realised that the default `net/http`
behaviour was in use - i.e. redirects were followed.

Signed-off-by: Fergus Morrow <[email protected]>
@FergusInLondon
Copy link
Author

I'm more than happy to adapt or change the approach if required - especially if there's any reason why the webhook filter is expected to follow redirects itself.

Bringing the webhook filter closer to traefik's ForwardAuth functionality - i.e. having more control over the response returned to the client - would be very useful though!

@FergusInLondon FergusInLondon changed the title webhook filter: allow client redirects via 302 responses (#3130) feature: allow client redirects via 302 responses (#3130) Jun 28, 2024
@@ -133,12 +138,16 @@ func reject(
ctx.Serve(rsp)
}

func redirect(ctx filters.FilterContext, username string, reason rejectReason, destination, debuginfo string) {
reject(ctx, http.StatusFound, username, reason, "", debuginfo, destination)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please provide the body of the function and not re-use redirect.
This will add a bit of code, but reduce the size of change.
reject should only be used for rejection as 4xx, thanks!

@@ -15,15 +15,17 @@ import (
)

const headerToCopy = "X-Copy-Header"
const webhookRedirectLocation = "https://example.com/auth"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use: "https://redirect.example/auth" as by RFC this is in .example, so better than in .com.

@szuecs szuecs added the major moderate risk, for example new API, small filter changes that have no risk like refactoring or logs label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major moderate risk, for example new API, small filter changes that have no risk like refactoring or logs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants